import 'package:flutter/material.dart';
import 'package:flutter_syt/starter/app_context.dart';
import 'package:flutter_syt/starter/processor.dart';
import 'package:flutter_syt/starter/registry.dart';

enum AppEnvironment { ENV_DEV, ENV_QA, ENV_PROD }

mixin EnvProvider {
  String get apiUrl;

  String get privacyUrl;

  String get articleUrl;
  String get userMallUrl;

  String get userPointUrl;

  @protected
  AppEnvironment get env;

  bool get isDebug => env == AppEnvironment.ENV_DEV;

  bool get isQa => env == AppEnvironment.ENV_QA;

  bool get isProd => env == AppEnvironment.ENV_PROD;
}



class EnvDevProvider with EnvProvider {
  @override
  String get apiUrl => "http://app-dev-api.oceanpika.com";
  String get articleUrl => "http://app-dev-article.oceanpika.com";
  String get userMallUrl => "http://app-dev-mall.oceanpika.com";
  String get userPointUrl =>
      "http://app-dev-mall.oceanpika.com/mall/myIntegral";

  @override
  String get privacyUrl => throw UnimplementedError();

  @override
  AppEnvironment get env => AppEnvironment.ENV_DEV;
}

class EnvQAProvider with EnvProvider {
  @override
  String get apiUrl => "http://app-test-api.oceanpika.com";
  String get articleUrl => "http://app-test-article.oceanpika.com";
  String get userMallUrl => "http://app-test-mall.oceanpika.com";
  String get userPointUrl =>
      "http://app-test-mall.oceanpika.com/mall/myIntegral";

  @override
  String get privacyUrl => throw UnimplementedError();

  @override
  AppEnvironment get env => AppEnvironment.ENV_QA;
}

class EnvProductProvider with EnvProvider {
  @override
  String get apiUrl => "https://app-api.theworldgames2025.com";
  String get articleUrl => "https://app-article.theworldgames2025.com";
  String get userMallUrl => "https://app-mall.theworldgames2025.com";
  String get userPointUrl => "https://app-mall.theworldgames2025.com/mall/myIntegral";
  @override
  String get privacyUrl => throw UnimplementedError();

  @override
  AppEnvironment get env => AppEnvironment.ENV_PROD;
}

class EnvProcessor with Processor<Type> {
  @override
  Future<dynamic> postProcessor(AppContext appContext, [Type? type]) {
    for (Registry registry in appContext.registry) {
      if (registry is EnvProviderRegistry) {
        appContext.provider = registry.getByType(type!);
        break;
      }
    }

    return Future.value();
  }
}
